package com.example.service.impl;

import com.example.mapper.EmpMapper;
import com.example.mapper.StuMapper;
import com.example.pojo.JobOption;
import com.example.pojo.Student;
import com.example.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceimpl implements ReportService {


    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StuMapper stuMapper;


    @Override
    public JobOption getEmpJobData() {
        //调用mapper接口获得统计数据
        List<Map<String, Object>> list = empMapper.getEmpJobData();

        //组装结构,并返回
        List<Object> joblist = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> number = list.stream().map(dataMap -> dataMap.get("num")).toList();

        /*较详细的办法，不使用链式编程
        //准备两个空列表用于存储结果
        List<Object> joblist = new ArrayList<>();
        List<Object> number = new ArrayList<>();

        // 遍历整个 list 集合
        for (Map<String, Object> dataMap : list) {
            // 从当前行中取出 pos 字段的值
            Object posValue = dataMap.get("pos");

            // 从当前行中取出 num 字段的值
            Object numValue = dataMap.get("num");

            // 把这两个值分别添加到对应的列表中
            joblist.add(posValue);
            number.add(numValue);
        }*/

        return new JobOption(joblist, number);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        //调用mapper接口获得统计数据
        return empMapper.getEmpGenderData();
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return stuMapper.getStudentDegreeData();

    }
}
